'use strict';
(function(){
  function apply(){
    const roots=document.querySelectorAll('#color-search, #color-board, #tp-colorboard');
    (roots.length?roots:[document]).forEach(h=>{
      h.querySelectorAll('[data-hex],[data-color],[data-swatch]').forEach(el=>{
        const hex=el.getAttribute('data-hex')||el.getAttribute('data-color')||el.getAttribute('data-swatch'); if(!hex) return;
        const style=getComputedStyle(el); const hasBg=style.backgroundImage!=='none'||style.backgroundColor!=='rgba(0, 0, 0, 0)';
        el.style.setProperty('--sw', hex); if(!hasBg) el.style.background=hex;
      });
    });
  }
  document.addEventListener('DOMContentLoaded', apply);
})();
